<?php

class Db_Tables2_BLogsSalesApproval
{
	function __construct() {
		$this->dealers_db = Zend_Registry::get("dealers_db");
	}
	
	function GetNext($type, $target_id)
	{
		$result = array();
		
		$select = $this->dealers_db->select();
		$select->from("b_logs_sales_approval", "*");
		$select->where("type = ?", $type);
		$select->where("target_id =?", $target_id);
		$select->where("status =?", 0);
		
		$row = $this->dealers_db->fetchRow($select);
		
		if($row)
		{
			$result = array(
				"emp_id" => $row['emp_id'],
				"emp_name" => $row['emp_name']
			);
		}
		
		return $result;
	}
	
	/**
	 * 返回值 0=已无后续审批人 1=有后续审批人
	 */
	function MoveToNext($type, $target_id, $emp_id)
	{
		$result = 0;
		
		$set = array(
			"status" => 1,
			"updated_time" => date("Y-m-d H:i:s")
		);
		
		$where = "type='".$type."' and target_id='".$target_id."' and emp_id='".$emp_id."'";
		
		$this->dealers_db->update("b_logs_sales_approval", $set, $where);
		
		if(1)
		{
			$select = $this->dealers_db->select();
			$select->from("b_logs_sales_approval", "*");
			$select->where("type = ?", $type);
			$select->where("target_id =?", $target_id);
			$select->where("status =?", 0);

			$row = $this->dealers_db->fetchRow($select);

			if($row)
			{
				$result = 1;
			}
		}
		
		return $result;
	}
}